package com.qf.blog.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.qf.blog.entity.User;
import com.qf.blog.mapper.UserMapper;
import com.qf.blog.service.IUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author toString
 * @since 2024-05-22
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {

    @Override
    public User getUserByEmail(String email) {
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("email", email);
        return baseMapper.selectOne(queryWrapper);
    }

    @Override
    public Integer updateUserStatus(String code, int status) {
        return baseMapper.updateUserStatus(code,status);
    }

    @Override
    public User getUserByUserName(String username) {
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("username", username);
        return super.getOne(queryWrapper);
    }

    @Override
    public void updateUserHeaderUrl(String fileUrl, Integer id) {
        User user = new User();
        user.setId(id);
        user.setHeaderUrl(fileUrl);
        super.updateById(user);
    }

}
